﻿class randomTypoMovie extends MovieClip
{
    var txtLabel, moveFix, moveRange, moveTrigger, charSpeed, listener, soundOption, waitChar, description, randomList, textCount, fixLength, fixStr, previous_instance, onEnterFrame, end_charMotion, end_textCount;
    function randomTypoMovie()
    {
        super();
        txtLabel.text = "";
        moveFix = 7;
        moveRange = 10;
        moveTrigger = 12;
        charSpeed = 2;
        listener = [];
    } // End of the function
    function setText2(instance, str, wChar, cSpeed, mFix, mRange, mTrigger)
    {
        txtLabel._xscale = txtLabel._yscale = 100;
        txtLabel._x = Math.round(txtLabel._x);
        txtLabel._y = Math.round(txtLabel._y);
        if (str != undefined)
        {
            
            waitChar = wChar;
            charSpeed = cSpeed;
            moveFix = mFix;
            moveRange = mRange;
            moveTrigger = mTrigger;
            description = str;
            randomList = [];
            var _loc2;
            for (var _loc2 = 0; _loc2 <= str.length - 1; ++_loc2)
            {
                var _loc3 = description.charAt(_loc2);
                if (_loc3 != " ")
                {
                    randomList[_loc2] = (moveFix + Math.round(Math.random() * moveRange)) * (Math.round(Math.random()) - 5.000000E-001) * 2;
                    continue;
                } // end if
                randomList[_loc2] = 0;
            } // end of for
            textCount = 0;
            fixLength = 0;
            fixStr = "";
            previous_instance = instance;
            onEnterFrame = randomMotion;
            for (var _loc2 = 0; _loc2 <= listener.length; ++_loc2)
            {
                listener[_loc2].onTypoStart();
            } // end of for
        } // end if
    } // End of the function
    function setTextAtOnce(instance, str)
    {
        txtLabel.text = str;
        previous_instance = instance;
    } // End of the function
    function randomMotion()
    {
        txtLabel.text = fixStr;
        end_charMotion = true;
        var _loc2;
        for (var _loc2 = fixLength; _loc2 <= textCount; ++_loc2)
        {
            if (randomList[_loc2] != 0 && randomList[_loc2] != undefined)
            {
                end_charMotion = false;
                var _loc3 = randomList[_loc2];
                if (Math.abs(_loc3) <= moveTrigger)
                {
                    var _loc4 = Math.min(Math.max(description.charCodeAt(_loc2) + _loc3, cMin), cMax);
                    txtLabel.text = txtLabel.text + String.fromCharCode(_loc4);
                }
                else
                {
                    txtLabel.text = txtLabel.text + waitChar;
                } // end else if
                if (_loc3 > 0)
                {
                    randomList[_loc2] = randomList[_loc2] - 1;
                }
                else
                {
                    randomList[_loc2] = randomList[_loc2] + 1;
                } // end else if
                continue;
            } // end if
            if (fixLength == _loc2 - 1)
            {
                fixLength = _loc2;
                fixStr = description.substring(0, fixLength);
            } // end if
            txtLabel.text = txtLabel.text + description.charAt(_loc2);
        } // end of for
        if (textCount <= description.length)
        {
            textCount = textCount + charSpeed;
        }
        else
        {
            end_textCount = true;
        } // end else if
        if (end_charMotion && end_textCount)
        {
            this.stopAction();
        } // end if
    } // End of the function
    function stopAction()
    {
        var _loc2;
        for (var _loc2 = 0; _loc2 < listener.length; ++_loc2)
        {
            listener[_loc2].onTypoEnd();
        } // end of for
        delete this.onEnterFrame;
        delete this.randomList;
        delete this.textCount;
        delete this.end_textCount;
        delete this.end_charMotion;
        delete this.fixStr;
        delete this.fixLength;
    } // End of the function
    function clear()
    {
        delete this.onEnterFrame;
        delete this.previous_instance;
        txtLabel.text = "";
    } // End of the function
    function addListener(obj)
    {
        listener.push(obj);
    } // End of the function
    var cMin = 33;
    var cMax = 126;
} // End of Class
